package com.xc.otc;

import android.graphics.Rect;
import android.view.ViewGroup;

import com.fker.opt.JNIFKerLibs;

import java.util.Random;

public class ClickPosition {

    public static void feedTemplateCasualClick(ViewGroup view) {

        Rect anchorRect = new Rect();
        view.getGlobalVisibleRect(anchorRect);
        int width = (anchorRect.right - anchorRect.left);
        int height = (anchorRect.bottom - anchorRect.top);
        if (width == 0 || height == 0) {
            return;
        }
        int xArea = width / 6;
        int yArea = height / 16;
        int xRandomValues = width - xArea * 2;
        int yRandomValues = height - yArea * 2;
        if (xRandomValues <= 0) {
            xRandomValues = new Random().nextInt(100);
        }
        if (yRandomValues <= 0) {
            yRandomValues = new Random().nextInt(100);
        }

        int x = 0;
        try {
            x = xArea + new Random().nextInt(xRandomValues);
        } catch (Exception e) {
            e.printStackTrace();
        }
        int y = 0;
        try {
            y = yArea + new Random().nextInt(yRandomValues);
        } catch (Exception e) {
            e.printStackTrace();
        }

        JNIFKerLibs.send(view, x, y);
    }
}
